package com.lmx.repoDomain.repository;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.common.constants.InitContantType;
import com.lmx.common.context.ActionContextHolder;
import com.lmx.common.util.CommonUtil;
import com.lmx.persistence.service.CommonInitConstantService;
import com.lmx.repoDomain.tmodel.CommonInitConstant;

import io.katharsis.queryParams.QueryParams;
import io.katharsis.repository.annotations.JsonApiFindAll;
import io.katharsis.repository.annotations.JsonApiResourceRepository;

/**
 * 手机端初始化加载时的数据集合
 *
 * @author ytche
 * @date 2017年7月14日
 *
 */

@JsonApiResourceRepository(CommonInitConstant.class)
@Component
public class CommonInitConstantRepository extends
		BaseRepository<CommonInitConstant> {
	@Autowired
	private CommonInitConstantService service;

	@Override
	@JsonApiFindAll
	public Iterable<CommonInitConstant> findAll(final QueryParams requestParams) {
		Long tenantId = ActionContextHolder.getContext().getTenantId();
		Map<String, String> filter = CommonUtil
				.getKeyMapByFilter(requestParams);
		String type = filter.get("type");
		InitContantType typeEnum = InitContantType
				.getByValue(new Integer(type));
		//添加当前user所属租户列表
		switch (typeEnum) {
		case PC:
			return service.findAllOfPC(filter, tenantId);
		case MOBILE:
			return service.findAllOfMobile(filter, tenantId);
		case OFFICIAL_ACCOUNTS:
			return service.findAllOfOfficalAccount(filter, tenantId);
		}
		return null;
	}

}
